/*
 * @Author: zhengzhuang
 * @since: 2020-01-08 14:29:13
 * @lastTime     : 2020-01-08 15:12:05
 * @LastAuthor   : zhengzhuang
 * @文件相对于项目的路径: /wangyueche_driver/lib/pages/real_time_guest_pulling_module/itinerary_order/express_car_order.dart
 * @message: 行程订单快车订单   ExpressCarOrder
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/model/get_trip_order_list.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:C20Driver/service/request.dart';
import 'package:C20Driver/utils/toast.dart';
import 'package:C20Driver/widget/no_data_widget.dart';
import 'package:C20Driver/widget/spinkit.dart';

class ExpressCarOrder extends StatefulWidget {
  @override
  _ExpressCarOrderState createState() => _ExpressCarOrderState();
}

class _ExpressCarOrderState extends State<ExpressCarOrder>
    with AutomaticKeepAliveClientMixin {
  ScrollController _scrollController = new ScrollController();

  @override
  bool get wantKeepAlive => true;

  List _list;
  int _page = 1;

  @override
  void initState() {
    super.initState();
    _getItineraryOrder();
    _scrollController.addListener(() {
      if (_scrollController.position.pixels ==
          _scrollController.position.maxScrollExtent) {
        _getItineraryOrderPullUpLoading();
      }
    });
  }

  /// 获取行程订单列表 分为历史行程订单和行程中订单
  Future _getItineraryOrder() async {
    _list =
        await Request.getItineraryOrder(page: _page.toString(), type: '0010');
    if (mounted) {
      setState(() {
        _list = _list;
      });
    }
  }

  /// 上拉加载我的行程列表
  Future _getItineraryOrderPullUpLoading() async {
    List _value = await Request.getItineraryOrder(
        page: (_page + 1).toString(), type: '0010');
    if (mounted) {
      if (_value.length != 0) {
        setState(() {
          _page++;
          _list.addAll(_value);
        });
      } else {
        ToastX.center('没有更多数据');
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return NoDataWidget();
    // return _list == null
    //     ? Spinkit()
    //     : Container(
    //         alignment: Alignment.center,
    //         child: _list.length != 0
    //             ? ListView.builder(
    //                 controller: _scrollController,
    //                 itemCount: _list == null ? 0 : _list.length,
    //                 itemBuilder: (context, index) {
    //                   var item = (_list)[index];
    //                   return _itineraryOrderCard(item);
    //                 },
    //               )
    //             : NoDataWidget(),
    //       );
  }

  @override
  void dispose() {
    _scrollController.dispose();
    super.dispose();
  }

  // 行程订单卡片
  Widget _itineraryOrderCard(val) {
    var getTripOrderListData = GetTripOrderList.fromJson(val);
    return Container(
      width: ScreenUtil().setWidth(700.0),
      padding: EdgeInsets.only(
        left: ScreenUtil().setWidth(25.0),
        right: ScreenUtil().setWidth(25.0),
      ),
      child: InkWell(
        child: Card(
          child: Container(
            padding: EdgeInsets.all(ScreenUtil().setWidth(25.0)),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  alignment: Alignment.centerLeft,
                  child: Offstage(
                    offstage: getTripOrderListData.status != '0030',
                    child: Text(
                      '未发起收款',
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(30.0),
                          color: Colors.red),
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Icon(
                          Icons.access_time,
                          size: ScreenUtil().setWidth(16.0),
                          color: Color.fromARGB(255, 205, 205, 205),
                        ),
                        SizedBox(
                          width: ScreenUtil().setWidth(10.0),
                        ),
                        Text(
                          getTripOrderListData.depTime != null
                              ? getTripOrderListData.depTime
                              : '',
                          style: TextStyle(
                            fontSize: ScreenUtil().setSp(30.0),
                            color: Color.fromARGB(255, 102, 102, 102),
                          ),
                        ),
                      ],
                    ),
                    Text(
                      '￥${getTripOrderListData.price.toString() != null ? getTripOrderListData.price.toString() : "0.0"}',
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(32.0),
                        color: Colors.black,
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                  ],
                ),
                SizedBox(
                  height: ScreenUtil().setHeight(15.0),
                ),
                Row(
                  children: <Widget>[
                    Container(
                      width: ScreenUtil().setWidth(15.0),
                      height: ScreenUtil().setHeight(15.0),
                      decoration: BoxDecoration(
                        color: Color.fromARGB(255, 36, 142, 247),
                        shape: BoxShape.circle,
                      ),
                    ),
                    SizedBox(
                      width: ScreenUtil().setWidth(10.0),
                    ),
                    Container(
                      width: ScreenUtil().setWidth(600.0),
                      child: Text(
                        getTripOrderListData.depAre,
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: ScreenUtil().setSp(30.0),
                          color: Color.fromARGB(255, 102, 102, 102),
                        ),
                      ),
                    ),
                  ],
                ),
                SizedBox(
                  height: ScreenUtil().setHeight(15.0),
                ),
                Row(
                  children: <Widget>[
                    Container(
                      width: ScreenUtil().setWidth(15.0),
                      height: ScreenUtil().setHeight(15.0),
                      decoration: BoxDecoration(
                        color: Color.fromARGB(255, 255, 153, 0),
                        shape: BoxShape.circle,
                      ),
                    ),
                    SizedBox(
                      width: ScreenUtil().setWidth(10.0),
                    ),
                    Container(
                      width: ScreenUtil().setWidth(600.0),
                      child: Text(
                        getTripOrderListData.destArea,
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: ScreenUtil().setSp(30.0),
                          color: Color.fromARGB(255, 102, 102, 102),
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
        onTap: () => NavigatorUtil.jump(
            context, '/itineraryOrderDetails?id=${getTripOrderListData.id}'),
      ),
    );
  }
}
